package com.zou.baidu_music_radio.utils;

import android.app.Activity;
import android.widget.Toast;

/**
 * Toast工具，可重复使用toast对象，避免多toast排队显示，较长时间才消失
 * Created by zou on 2016/3/4.
 */
public class ToastUtil {
    Toast toast = null;
    Activity activity;
    static int[] duration = {Toast.LENGTH_SHORT, Toast.LENGTH_LONG};

    public ToastUtil(Activity activity) {
        this.activity = activity;
    }

    /**
     * @param text         要显示的文字
     * @param durationType 0：显示时间长度为short  1：显示时间长度为long
     * @author zou
     */
    public void showToast(String text, int durationType) {

        if (toast != null) {
            toast.setDuration(duration[durationType]);
            toast.setText(text);
        } else {
            toast = Toast.makeText(activity, text, duration[durationType]);
        }

        toast.show();
    }
}
